function [ImageData,ImageWidth,ImageHeight] = OpenImage(ImageFile)
%OpenImage  
%  [ImageData,ImageWidth,ImageHeight] = OpenImage(ImageFile);
%  
%  OpenImage: Open and gray the image file.
%          ImageData: Image data with uint8 on bit.
%          ImageWidth: Image's width.
%          ImageHight: Image's height.
% 
%  See also 
% 
%  Further Information:  
%       http://code.google.com/p/jameshuang-imagerecognition/  
%  
%   Copyright (c) 2013 by James Huang. 
%   e-mail: jameshuang@mail.com  
%   $Revision: 0.0 $  $Date: 2013/07/23 $ 


img = imread(ImageFile);

[ImageHeight ImageWidth dim] = size(img);
if (dim ~= 3 | dim ~=4)
  error('The image not RGB format')
end
T = zeros([ImageHeight, ImageWidth ]);
A = [0.299 0.587 0.114];
for i=1:ImageHeight
  for j=1:ImageWidth
    B = [img(i,j,1) img(i,j,2) img(i,j,3)]';
    T(i,j) = A* double(B);
  end
end

ImageData = uint8(T);     